<template>
  <div class="">
    <!-- 自定义导航栏 -->
    <gh-navbar id="navbar" :showback="true" title="我的律师" url="/pages/my/my" />
    <div class="none" v-show="condition">
      <image class="none-img" :src="imgBaseUrl + 'none.png'" mode="widthFix" />
    </div>
    <!-- 内容盒子 -->
    <div class="mylawer">
      <div class="item" v-for="item in dataList" :key="item.id" @click="handleClickToDetail(item.lawyer.id)">
        <div class="info">
          <image class="avatar" :src="item.lawyer.avatar" mode="widthFix"></image>
          <div class="lawer">
            <div class="top">
              <div class="name">{{item.lawyer.reply_realname}}</div>
              <div class="status">
                <text v-if="item.status == 3">已关闭</text>
                <text class="nopay" v-else-if="item.status == 0">未支付</text>
                <text v-else-if="item.status == 1">已支付</text>
                <text v-else-if="item.status == 2">已完成</text>
              </div>
            </div>
            <div class="bottom">
              <div class="company">{{item.lawyer.affiliated_company}}</div>
              <div class="money">￥{{item.payment_money}}</div>
            </div>
          </div>
        </div>
        <div class="btn">
          <div class="button" v-if="item.status == 0" @click.stop="handlePay(item.id)">立即支付</div>
            <div class="button" v-else-if="item.status == 1 && item.receipt_status == 0" @click.stop="handleWait(item)">待接单</div>
            <div class="button" v-else-if="item.status == 1 && item.receipt_status == 1" @click.stop="handleConfrim(item)">完成服务</div>
            <navigator
              :url="'/pageMy/menu/comment?orderid='+item.id+'&type=2&lawyerid='+item.lawyer.id"
              class="button"
              v-else-if="item.status == 2 && !item.score"
            >评价</navigator>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dataList: [],
      imgBaseUrl: this.$store.state.imgBaseUrl,
      condition: false
    };
  },
  onShow() {
    // 先清空数据再重新获取新数据
    this.dataList = []
    this.init();
  },
  methods: {
    // 支付
    handlePay(orderid) {
      this.$gh.pay(orderid).catch(err => {
        uni.showToast({
          icon: 'none',
          title: '支付失败',
          duration: 2000
        });
      });
    },
    handleWait() {
      uni.showToast({
        icon: 'none',
        title: '律师未接单',
        duration: 2000
      });
    },
    handleClickToDetail(id){
      uni.navigateTo({
         url: `/pages/lawer/detail?id=${id}`
      });
    },
    async handleConfrim(item) {
      await this.$store.dispatch("modal", "是否确定完成服务？");
      // 请求
      const res = await this.$gh.request("member.order", {
        data: {
          op: "editComplete",
          orderid: item.id
        }
      }).catch((err) => {
        
      })
      if(res.code == 200){
        uni.navigateTo({
            url: `/pageMy/menu/comment?orderid=${item.id}&type=2&lawyerid=${item.lawyer.id}`
        });
      }
    },
    async init(page = 1) {
      let res = await this.$gh
        .request("member.order", {
          data: {
            op: "getOrderList",
            service_type: 2,
            consultation_type: 5,
            page,
            psize: 20
          }
        })
        .catch(err => {
          if (err.code == 41009) {
            this.$store.dispatch("login", err.message);
          }
          if(err.code == 201){
            this.condition = true
          }
        });
      this.dataList = this.dataList.concat(res.data.list)
      this.length = res.data.list.length;
    }
  },
  onReachBottom(){
    if (this.length < 20) return;
    this.page++;
    this.init(this.page);
  }
};
</script>
<style lang='less' scoped>
@import url("../../common/util.less");
.none {
  font-size: 30rpx;
  color: @font-color;
  text-align: center;
  .none-img{
    width: 50%;
    margin-top: 100rpx;
  }
}
.mylawer {
  padding: 25rpx 25rpx 0;
  .item {
    padding: 25rpx;
    background-color: #fff;
    border-radius: 30rpx;
    margin-bottom: 25rpx;
    .info {
      .flex();
      .avatar {
        width: 100rpx;
        height: 100rpx;
        border-radius: 50%;
        margin-right: 10rpx;
      }

      .lawer {
        flex: 1;
        .top {
          .gh-between();
          padding-bottom: 10rpx;
          .name {
            font-size: 30rpx;
            color: @deep-color;
          }

          .status {
            text {
              font-size: 24rpx;
              color: @font-color;
            }
            .nopay{
              color: red;
            }
          }
        }

        .bottom {
          .gh-between();
          .company {
            font-size: 24rpx;
            color: @font-color;
          }

          .money {
            font-size: 24rpx;
            color: red;
          }
        }
      }
    }

    .btn {
      display: flex;
      justify-content: flex-end;
      margin-top: 15rpx;
      .button{
        padding: 10rpx 20rpx;
        font-size: 30rpx;
        color: #fff;
        border-radius: 30rpx;
        background-color: #849aff;
      }
    }
  }
}
</style>